﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StockFinder.Model;

namespace StockFinder.Indicators.Day
{
    public abstract class BaseDayIndicator : IDailyPriceIndicator
    {
        public int LookbackPeriod { get; private set; }
        public string IndicatorName { get; private set; }

        protected BaseDayIndicator(int lookbackPeriod, string indicatorName)
        {
            LookbackPeriod = lookbackPeriod;
            IndicatorName = indicatorName;
        }

        #region IDailyPriceIndicator Members

        public abstract void ApplyIndicator(List<DailyPrice> prices);

        #endregion

        /// <summary>
        /// Performs various initialization tasks and also determines whether
        /// prices list passes various checks
        /// </summary>
        /// <param name="prices"></param>
        /// <returns></returns>
        protected bool Initialize(List<DailyPrice> prices)
        {
            var result = false;

            prices.ForEach(p => p.DayIndicators[IndicatorName] = 0);

            if (prices != null && prices.Count >= LookbackPeriod)
            {
                result = true;
                //some prices might be skipped due to starting period so make sure all prices are filled
            }

            return result;
        }
    }
}
